package com.service.Impl;

import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ChannelDto;
import com.heima.model.common.dtos.ResponseResult;
import com.service.AdChannerlService;
import com.service.Impl.AdChannerlServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@SpringBootTest()
@RunWith(SpringRunner.class)
public class test {
    @Autowired
    private AdChannerlServiceImpl adChannerlService;

    @Autowired
    private RestTemplate restTemplate;

    //查询频道测试
    @Test
    public void test1(){
        ChannelDto channelDto = new ChannelDto();
        channelDto.setPage(1);
        channelDto.setSize(2);
        channelDto.setName("o");
        ResponseResult byNameAndPage = adChannerlService.findByNameAndPage(channelDto);
        List<AdChannel> data = (List<AdChannel>) byNameAndPage.getData();
        System.out.println("-----------------------"+data);

    }

    @Test
    //查询单个频道测试
    public  void  findOneTest(){
        AdChannel adChannel = new AdChannel();
        adChannel.setId(46);
        adChannel.setName("nodejs");
        adChannel.setOrd(1);
        ResponseResult result = adChannerlService.saveChannel(adChannel);
        System.out.println("0000000000000000");
        System.out.println(result.getCode());
        String errorMessage = result.getErrorMessage();
        System.out.println(errorMessage);
    }

    //执行添加操作
    @Test
    public void savaTest(){
        AdChannel adChannel = new AdChannel();
        adChannel.setId(50);
        adChannel.setName("GO");
        adChannel.setOrd(1);

        String url="http://localhost:9001/channel/save";
        ResponseResult result = restTemplate.postForObject(url, adChannel, ResponseResult.class);
        System.out.println("00000000000000000000");
        String errorMessage = result.getErrorMessage();
        System.out.println(errorMessage+"---"+result.getCode());


    }




}
